

/*----------------------------------------------------------------------------
 * Name:    systick.c
 * Purpose: IRQ Handler
 * Note(s):
 *----------------------------------------------------------------------------
 * This file is part of the uVision/ARM development tools.
 * This software may only be used under the terms of a valid, current,
 * end user license from KEIL for a compatible version of KEIL software
 * development tools. Nothing else gives you the right to use this software.
 *
 * This software is supplied "AS IS" without warranties of any kind.
 *
 * Copyright (c) 2011 Keil - An ARM Company. All rights reserved.
 *----------------------------------------------------------------------------*/
#include "LPC17xx.H" /* LPC17xx definitions           */
#include "glob.h"
#define MAX_TIMER_COUNT 8
#define IDEL 0
#define INUSE 1
#define INUSE_IDEL 2
#define INUSE_PAUSE 3

/*----------------------------------------------------------------------------
  Systick Interrupt Handler
 *----------------------------------------------------------------------------*/
static unsigned long long SystemTime = 0;
uint16_t Time480ms = 0;
unsigned int time1s = 0;
extern unsigned int zhilengtime;

void CounterFunc(STR_HMSTIME *time)
{
    time->Second++;
    if (time->Second >= 60)
    {
        time->Second = 0;
        time->Minute++;
        if (time->Minute >= 60)
        {
            time->Minute = 0;
            time->Hour++;
        }
    }
}

void SysTick_Handler(void)
{
    SystemTime += 1;
    SysTicks++;
    Time480ms++;
    time1s++;

    if (time1s >= 1000)
    {
        time1s = 0;
        zhilengtime++;
        if (WorkFlow.process != WORK_IDLE)
        {
            WorkFlow.work_time.Second++;
            if (WorkFlow.work_time.Second >= 60)
            {
                WorkFlow.work_time.Second = 0;
                WorkFlow.work_time.Minute++;
                lcd_data[11] = WorkFlow.work_time.Minute;
                if (WorkFlow.work_time.Minute >= 60)
                {
                    WorkFlow.work_time.Minute = 0;
                    WorkFlow.work_time.Hour++;
                    lcd_data[10] = WorkFlow.work_time.Hour;
                }
            }
        }
        if (WorkFlow.process == WORK_SAMPLE)
        {
            CounterFunc(&WorkFlow.sample_time);
        }
        else if (WorkFlow.process == WORK_SAMPLE_WAIT)
        {
            CounterFunc(&WorkFlow.cycle_time);
        }
        else if (WorkFlow.process == WORK_ANALYSIS && lcd_data[5] >= (*p_cfg.analysis_temp))
        {
            CounterFunc(&WorkFlow.analysis_time);
        }
        else if (WorkFlow.process == WORK_DEFROST_WAIT)
        {
            CounterFunc(&WorkFlow.wait_time);
        }
        else if (WorkFlow.process == WORK_DEFROST)
        {
            CounterFunc(&WorkFlow.defrost_time);
        }
    }

    if ((Time480ms % 20) == 0)
    {
        KeyInfo.CurKey = READKEYUP | READKEYRE | READKEYEN | READKEYST | READKEYDN;
        TimmingScanKey(&KeyInfo);
    }

    if (Time480ms >= 480)
    {
        Time480ms = 0;
        SysTime.SecFlag = 1;
    }

    ReadFlowCn++;

    if (Flow.CalTime)
    {
        Flow.CalTime--;

        if (Flow.CalTime == 0)
        {
            Flow.CalFlag = 0x11;
        }
    }

    if (Flow2.CalTime)
    {
        Flow2.CalTime--;

        if (Flow2.CalTime == 0)
        {
            Flow2.CalFlag = 0x11;
        }
    }

    if (NoKeyAck)
    {
        NoKeyAck--;
    }
}
